#include "CommonFunc.h"

void CommonFunc::drawExitBtn(QPainter* painter, const QRect& rect)
{
	if (painter == nullptr) {
		return;
	}
	QPixmap pixmap(":/UI/icon/common/menu_back.png");
	if (pixmap.isNull()) {
		return;
	}
	painter->drawPixmap(rect, pixmap);
}

void CommonFunc::drawFormName(QPainter* painter, const QRect& rect, QString name)
{

	QFont font;
	font.setPixelSize(20);
	font.setFamily("Source Han Sans K");
	painter->setFont(font);
	QPen pen(QColor(153, 153, 153));
	painter->setPen(pen);
	QFontMetrics metrics(font);
	int w = metrics.width(name);
	painter->drawText(rect, Qt::AlignRight | Qt::AlignVCenter, name);

}

void CommonFunc::initNode(Node<UIElement>* head, Node<UIElement>* tail, const int&displayNum)
{
	for (int i = 0; i < (displayNum - 1) / 2; i++) {
		head = head->prev;
		tail = tail->next;
	}
	Node<UIElement>* temp = head;
	while (temp != tail) {
		temp = temp->prev;
		if (temp->data != nullptr) {
			temp->data->setRect(QRect(0, 0, 0, 0));
		}
	}

}
